package com.demo.consumer.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <h3>mq-demo</h3>
 * <p></p>
 *
 * @author : zhengyue
 * @date : 2023/11/3 9:27
 **/
@Configuration
public class DirectConfiguration {
    @Bean
    public DirectExchange directExchange() {
        // 方案1
        // return ExchangeBuilder.directExchange("apitest.direct").build();
        // 方案2
        return new DirectExchange("apitest.direct");
    }

    @Bean
    public Queue directQueue1() {
        // 方案 1
        // return QueueBuilder.durable("apitest.direct"); // 持久化
        // 方案 2 默认持久化
        return new Queue("apitest.direct.queue1");
    }

    @Bean
    public Binding DirectBinding(Queue directQueue1, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue1).to(directExchange).with("blue");
    }

    @Bean
    public Queue directQueue2() {
        // 方案 1
        // return QueueBuilder.durable("apitest.direct"); // 持久化
        // 方案 2 默认持久化
        return new Queue("apitest.direct.queue2");
    }

    @Bean
    public Binding DirectBinding2() {
        return BindingBuilder.bind(directQueue2()).to(directExchange()).with("red");
    }
}
